<?php

/*
  |--------------------------------------------------------------------------
  | Web Routes
  |--------------------------------------------------------------------------
  |
  | This file is where you may define all of the routes that are handled
  | by your application. Just tell Laravel the URIs it should respond
  | to using a Closure or controller method. Build something great!
  |
 */

Route::get('/', function () {
//    $orders = \App\Models\Order::
//            with('orderDetail')
////            ->where('created_at','>', Carbon\Carbon::yesterday()->hour(0)->minute(0)->second(0))
////            ->where('created_at','<', Carbon\Carbon::now())
//            ->get();
//    $rfids = [];
//    $orderIds = [];
//    foreach($orders as $order){
//        $rfids = array_merge($rfids,$order->orderDetail->pluck('rfid')->toArray());
//        $orderIds[] = $order->id;
//    }
//    \App\Models\GoodsNexus::whereIn('rfid',$rfids)->update(['state'=>0]);
//    \App\Models\Order::whereIn('id',$orderIds)->delete();
//    \App\Models\OrderDetail::whereIn('order_id',$orderIds)->delete();
//    return '重置成功';
    return view('welcome');
});
Route::get('/clear_order','TestController@clearOrder');//通过用户手机号码清理订单（测试使用）
Route::get('/clear_order_num','TestController@deleteOrder');//通过订单号清理订单（测试使用）
Route::get('/personal', function () {
    return view('wechat.user.personal');
});
/* ======熊猫立方后台的路由======= */
//熊猫立方的后台登录
Route::any('/admin/login', 'Admin\LoginController@login');
//熊猫立方的后台登出
Route::any('/admin/logout', 'Admin\LoginController@logout');

Route::group(['prefix' => '/admin', 'namespace' => 'Admin', 'middleware' => ['web', 'admin.login']], function () {
    Route::any('/', 'LoginController@index');
    /* ====商品管理的路由==== */
    Route::group(['prefix' => 'commodity'], function () {
        //商品管理的列表
        Route::any('/', 'CommodityController@index')->middleware('permission:goods.list');
        Route::get('/show/{goods_id}', 'CommodityController@show')->middleware('permission:goods.list');
        Route::any('/update/{goods_id}', 'CommodityController@update')->middleware('permission:goods.edit');
        Route::post('/store', 'CommodityController@store')->middleware('permission:goods.create');
        Route::get('/destroy/{goods_id}', 'CommodityController@destroy')->middleware('permission:goods.destroy');
        Route::post('/status', 'CommodityController@status');
        Route::post('/import', 'CommodityController@import');
        Route::get('/download', 'CommodityController@download');
        Route::post('/rfidimport/{goods_id}', 'CommodityController@rfidimport');
        Route::get('/rfiddownload', 'CommodityController@rfiddownload');
    });
    /* ====商品分类的路由==== */
    Route::group(['prefix' => 'classification'], function () {
        Route::get('/', 'GoodsactionController@index')->middleware('permission:goodsClass.list');
        Route::get('/edit_class', 'GoodsactionController@edit_class')->middleware('permission:goodsClass.edit');
        Route::post('/get_all_children', 'GoodsactionController@getAllChildren');
        Route::post('/add_class', 'GoodsactionController@add_class')->middleware('permission:goodsClass.create');
        Route::post('/editpost_class', 'GoodsactionController@editpost_class')->middleware('permission:goodsClass.edit');
        Route::post('/delete', 'GoodsactionController@delete')->middleware('permission:goodsClass.destroy');
    });
    /* ====订单管理的路由==== */
    Route::group(['prefix' => 'order'], function () {
        Route::any('/', 'OrderController@index')->middleware('permission:order.list');
        Route::get('/show/{orders_id}', 'OrderController@show')->middleware('permission:order.list');
        Route::post('/status', 'OrderController@status')->middleware('permission:order.status');
    });
    /* ====会员管理的路由==== */
    Route::group(['prefix' => 'vip'], function () {
        Route::any('/', 'VipController@index')->middleware('permission:order.list');
        Route::get('/show/{vip_id}', 'VipController@show')->middleware('permission:order.list');
        Route::any('/update/{vip_id}', 'VipController@update')->middleware('permission:order.edit');
        Route::post('/status', 'VipController@status')->middleware('permission:order.status');
    });
    /* ====店铺管理的路由===== */
    Route::group(['prefix' => 'shop', 'middleware' => 'permission:shop'], function () {
        Route::get('/', 'ShopController@index');     //点击店铺管理的时候，进入店铺首页
        Route::any('/index', 'ShopController@index'); //输入地址的时候或者post提交的时候，访问店铺首页
        Route::get('/index/{shop_name}', 'ShopController@index'); //get查询的时候，访问店铺首页
        Route::any('/show/{shop_id}', 'ShopController@show'); //点击查看详情的时候，访问店铺详情页
        Route::post('/change_key', 'ShopController@change');  //修改店铺密匙的post提交
        Route::post('/save_data', 'ShopController@change');   //修改店铺信息的post提交
        Route::post('/upload', 'ShopController@upload');      //上传excel文件
        Route::get('/download', 'ShopController@download');   //下载excel模板文件
    });
    /* ====RFID管理的路由==== */
    Route::group(['prefix' => 'rfidmanage'], function () {
        Route::any('/', 'RfidmanageController@index')->middleware('permission:rfid.list');
        Route::get('/warehouse', 'RfidmanageController@warehouse')->middleware('permission:rfid.warehouse');
        Route::get('/download', 'RfidmanageController@download')->middleware('permission:rfid.list');
        Route::post('/import', 'RfidmanageController@import')->middleware('permission:rfid.list');
        Route::get('/destroy/{rfid_id}', 'RfidmanageController@destroy')->middleware('permission:rfid.destroy');
        Route::get('/housedownload', 'RfidmanageController@housedownload')->middleware('permission:rfid.warehouse');
        Route::post('/houseimport', 'RfidmanageController@houseimport')->middleware('permission:rfid.warehouse');
        Route::get('/associated', 'RfidmanageController@associated')->middleware('permission:rfid.warehouse');
    });
    /* =======运营统计的路由============= */
    Route::group(['prefix' => 'operation', 'middleware' => 'permission:operation'], function () {
        Route::get('/', 'OperationController@index');
    });
    /* ====系统管理的路由(超级管理员才能访问)==== */
    Route::group([], function () {
        //账号管理
        Route::group(['prefix' => 'user'], function () {
            //账号列表
            Route::get('/', 'UserController@index')->middleware('role:super_admin');
            //账号添加页面
            Route::get('/create', 'UserController@create')->middleware('role:super_admin');
            //账号添加操作
            Route::post('/', 'UserController@store')->middleware('role:super_admin');
            //账号修改页面
            Route::get('/{id}/edit', 'UserController@edit')->middleware('role:super_admin');
            //账号修改操作
            Route::put('/{id}', 'UserController@update')->middleware('role:super_admin');
            //账号删除操作
            Route::delete('/{id}', 'UserController@destroy')->middleware('role:super_admin');
        });
        //角色管理
        Route::group(['prefix' => 'role'], function () {
            //角色列表
            Route::get('/', 'RoleController@index')->middleware('role:super_admin');
            //角色添加页面
            Route::get('/create', 'RoleController@create')->middleware('role:super_admin');
            //角色添加操作
            Route::post('/', 'RoleController@store')->middleware('role:super_admin');
            //角色修改页面
            Route::get('/{id}/edit', 'RoleController@edit')->middleware('role:super_admin');
            //角色修改操作
            Route::put('/{id}', 'RoleController@update')->middleware('role:super_admin');
            //角色删除操作
            Route::delete('/{id}', 'RoleController@destroy')->middleware('role:super_admin');
        });
    });
});

//微信前台
Route::group(['namespace' => 'Wechat'], function () {

    //微信回调页
    Route::get('wechat/oauth', 'WechatController@oauth');
    Route::post('check_door', 'EntranceController@checkDoor');

    //用户
    Route::post('register', 'AuthController@postRegister');
    Route::get('register', 'AuthController@getRegister');
    Route::post('send_code', 'AuthController@sendSmsCode');
    Route::get('reg_success', 'AuthController@regSuccess');
    Route::get('agreement', function () {
        return view('wechat.user.agreement');
    });

    //AB门
    Route::get('check_user', 'EntranceController@checkUser');
    Route::get('welcome', 'EntranceController@welcome');
    Route::post('inform', 'EntranceController@inform');
    Route::post('rfid_receive', 'EntranceController@rfidReceive');
    Route::get('qrcode', 'EntranceController@qrCodeHtml');
    Route::get('qrcode_png', 'EntranceController@qrCodePng');

    //订单
    //订单列表
    Route::get('order_list', 'OrderController@orderList');
    //微信支付成功异步通知
    Route::post('order_notify', 'OrderController@orderNotify');
    Route::get('/pay_success', 'OrderController@paySuccess');
    Route::get('/order_detail', 'OrderController@orderDetail');

    Route::get('/my', 'UserController@index');
    Route::get('/my/order', 'UserController@order');
    Route::get('/my/bill', 'UserController@bill');
});
